package com.jnshu.web;

import com.jnshu.pojo.Course;
import com.jnshu.service.FileuploadClient;
import com.jnshu.service.LearningService;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Validated
@Log
@RestController
public class LearningController {

    @Autowired(required = false)
    LearningService learningService;
    @Autowired(required = false)
    FileuploadClient fileuploadClient;

    //视频列表
    @GetMapping(value = "/course/list")
    public ResultBean courseList(@RequestParam(required = false) Integer classify, @RequestParam(required = false) Integer subject, @RequestParam(required = false) Integer grade, @RequestParam(required = false) String title,
                          @RequestParam(required = false) Integer status,
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("_____________________________________________");
        log.info("方法courseList进来的参数为" + "," + pageSize + "," + pageNum);
        return learningService.SelectList(classify,subject,grade,title,status,pageNum, pageSize);
    }


    //上下架
    @PutMapping(value = "/course/status")
    public ResultBean aStatus(@RequestParam long id,
                              @RequestParam int status) {
        log.info("_____________________________________________");
        log.info("方法aStatus进来的参数为" + "," + id + "," + status);

        return learningService.aStatus(id, status);
    }

    //删除课程
    @DeleteMapping(value = "/course")
    public ResultBean deleteByPrimaryKey(@RequestParam Long id) {
        log.info("_____________________________________________");
        log.info("方法deleteByPrimaryKey进来的参数为" + "," + id);
        return learningService.deleteByPrimaryKey(id);
    }

    //新增视频
    @PostMapping(value = "/video")
    public ResultBean aInsertVideo(@RequestParam Integer classify, @RequestParam Integer subject, @RequestParam Integer grade, @RequestParam String title,
                                   @RequestParam String teacherName, @RequestParam String job, @RequestParam String cover, @RequestParam String videoLink,
                                   @RequestParam String introduction, @RequestParam Integer status) {
        log.info("_____________________________________________");
        log.info("方法aInsertVideo进来的参数为" + ",");
        return learningService.aInsertVideo( classify, subject, grade, title, teacherName, job, cover, videoLink,introduction, status);
    }

    //更新视频
    @PutMapping(value = "/video")
    public ResultBean aUpdateVideo(@RequestParam Long id, @RequestParam Integer classify, @RequestParam Integer subject, @RequestParam Integer grade, @RequestParam String title,
                                   @RequestParam String teacherName, @RequestParam String job, @RequestParam String cover, @RequestParam String videoLink,
                                   @RequestParam String introduction, @RequestParam Integer status) {
        log.info("_____________________________________________");
        log.info("方法aUpdateVideo进来的参数为" + "," + id);
        return learningService.aUpdateVideo(id, classify, subject, grade, title, teacherName, job, cover,videoLink, introduction, status);
    }

    //视频详情
    @GetMapping("/video")
    public ResultBean VideotList(@RequestParam Long id) {
        log.info("_____________________________________________");
        log.info("方法VideotList进来的参数为" + "," + id);
        return learningService.VideotList(id);
    }


    //文章详情
    @GetMapping("/content")
    public ResultBean ContentList(@RequestParam Long id) {
        log.info("_____________________________________________");
        log.info("方法ContentList进来的参数为" + "," + id);
        return learningService.ContentList(id);
    }

    //新增文章
    @PostMapping(value = "/content")
    ResultBean aInsertContent(@RequestParam Integer classify, @RequestParam Integer subject, @RequestParam Integer grade, @RequestParam String title,
                              @RequestParam String teacherName, @RequestParam String job, @RequestParam String cover,
                              @RequestParam String introduction, @RequestParam Integer status) {
        log.info("_____________________________________________");
        log.info("方法aInsertContent进来的参数为" + ",");
        return learningService.aInsertContent(classify, subject, grade, title, teacherName, job, cover, introduction, status);
    }

    //更新文章
    @PutMapping(value = "/content")
    public ResultBean aUpdateContent(@RequestParam Long id,
                                     @RequestParam Integer classify, @RequestParam Integer subject, @RequestParam Integer grade, @RequestParam String title,
                                     @RequestParam String teacherName, @RequestParam String job, @RequestParam String cover,
                                     @RequestParam String introduction, @RequestParam Integer status) {
        log.info("_____________________________________________");
        log.info("方法aUpdateContent进来的参数为" + "," + id);
        return learningService.aUpdateContent(id, classify, subject, grade, title, teacherName, job, cover, introduction, status
        );
    }
       //上传封面
    @PostMapping("/course/image")
    public  ResultBean image(@RequestPart(value = "file") MultipartFile file){
        log.info("_____________________________________________");
        log.info("方法image进来的参数为" + "," + file.getOriginalFilename()+file.getContentType());
        return fileuploadClient.image(file);
    }
}
